<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JS判断奇偶数</title>
</head>


<body>
<input type="text" id="numberInput">
<button onclick="checkNumber()">判断奇偶性</button>
<script>
function isEven(num) {
  return num % 2 === 0;
}
function checkNumber() {
  var inputNumber = document.getElementById('numberInput').value;
  if(inputNumber.trim() !== '') { 
    var number = parseInt(inputNumber, 10);
    if(isNaN(number)) {
      alert("请输入有效的整数！");
    } else {
      var result = isEven(number) ? "是偶数" : "不是偶数";
      alert("数字 " + number + " " + result);
    }
  } else {
    alert("请输入一个数字！");
  }
}

window.onload = function() {
  var randomNumber = Math.floor(Math.random() * 10001);
  document.getElementById('numberInput').value = randomNumber;
};
</script>
</body>
</html>